package com.zhida84.Impl;
/**
 * 
 * @author shazhengbo sunchangxing
 *
 */
import java.sql.ResultSet;

import com.zhida84.Dao.DBSQL;
import com.zhida84.Dao.ShowDetailDao;

public class ShowDetailImpl implements ShowDetailDao {

	DBSQL db = new DBSQL();
     @Override
	public ResultSet showAll(int id) {
		String sql = "select * from recruittable left join merchanttable on recruittable.merId=merchanttable.merId where recruittable.recruitId=?";
		return db.getQuery(sql, new Object[] { id });
	}
	@Override
	public ResultSet showMsgAll(Integer recId, Integer userId) {
		String sql= "SELECT   IF(LENGTH(m.contentInfo) > 100, CONCAT(left(m.contentInfo, 100), '...'), m.contentInfo) AS contentInfo,  u.userReName FROM messagetable m INNER JOIN usertable u  ON m.userId = u.userId WHERE m.recId = ? AND m.userId = ?";
		return db.getQuery(sql, new Object[] { recId , userId});
	}
	@Override
	public ResultSet showMsgById(Integer id) {
		String sql= "SELECT contentInfo FROM messagetable  WHERE id = ?";
		return db.getQuery(sql, new Object[] { id});
	}
	@Override
	public ResultSet showMsgByUserId(Integer userId) {
		String sql = "SELECT IF(LENGTH(m.contentInfo) > 100, CONCAT(left(m.contentInfo, 100), '...'), m.contentInfo) AS contentInfo, r.jobName FROM messagetable m  INNER JOIN recruittable r  ON m.recId = r.recruitId WHERE m.userId = ?;";
		return db.getQuery(sql, new Object[] { userId });
	}
	@Override
	public ResultSet showCollectionByUserId(Integer userId) {
		String sql = "SELECT DISTINCT r.jobName,  c.id as collectionId,  r.recruitId, r.reType FROM collectiontable c INNER JOIN recruittable r  ON c.recId = r.recruitId WHERE c.userId= ?;";
		return db.getQuery(sql, new Object[] { userId });
	}
	@Override
	public int delColletionId(int id) {
		String sql = "delete from collectiontable where id= ?;";
		return db.getUpdate(sql, new Object[] { id });
	}

}
